#ifndef GRID_H
#define GRID_H
#include <QColor>
#include <QWidget>
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
class Grid : public QWidget
{
    Q_OBJECT
public:
    explicit Grid(QWidget *parent = 0);
    ~Grid();
    void paintEvent(QPaintEvent *);
    void paintGrid(QPainter &p);
    void paintUniverse(QPainter &p);
    void next_state();
    int gen(int x,int y);
    bool check_dump_state();
    bool valid(int x,int y);
    int randint(int l,int r);
    void draw_rect(int i,int j,int w,int h);
    void draw_plane(int i,int j);
    pair<int,int>turn(pair<int,int>o);
    void draw_star(int x,int y);
    void draw_ship(int x,int y);
    vector<pair<int,int>>generate_random_pointset(int size);
    void clear();

    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);

public slots:
    void run_game();
    void next_step();
    void set_normal();
    void set_rect();
    void set_plane();
    void set_star();
    void set_ship();
    void random_init();

signals:
    void _event(bool);

private:
    QTimer*mytimer;
//    map<int,map<int,int>>color;
    int color[maxn][maxn],nxc[maxn][maxn];
    int grid_size;
    QColor origin_color;
    int key_type;
    mt19937_64 rng;
    const int plane[5][2]={{0,0},{0,1},{1,0},{1,-1},{-1,-1}};
    const int ship[10][2]={{0,2},{1,1},{1,-2},{-1,2},{-2,2},{-2,1},{-2,0},{-2,-1},{-1,-2},{1,-2}};
};

#endif // GRID_H
